package view;

import java.awt.*;
import java.awt.event.*;

import beans.MaterialDeEstudo;
import javax.swing.*;


public class MaterialEstudoView implements IMaterialEstudoView {

	//private ActionListener listener = null;
	//private String action = null;
//
	private MaterialDeEstudo materialEstudo=null; 
	private JPanel BackPanel = null;
	private JScrollPane scrollPane=null;
	private JTextArea textArea=null;
	
	public MaterialEstudoView() {
		BackPanel = new JPanel();
		BackPanel.setLayout(new BoxLayout(BackPanel, BoxLayout.Y_AXIS));
		BackPanel.setPreferredSize(new Dimension(120, 0));
		textArea=new JTextArea();
		buildGUI();
	}
	
	public void setMaterialEstudo(MaterialDeEstudo materialEstudo) {
		this.materialEstudo=materialEstudo;
	}
	
	public MaterialDeEstudo getMaterialEstudo() {
		return this.materialEstudo;
	}
	
	public JPanel getPanel() {
		return BackPanel;
	}
	
	@Override
	public void show() throws Exception {
		scrollPane.setVisible(true);
	}

	@Override
	public void refresh() {
		textArea.setText(materialEstudo.getConteudo());
	}

	@Override
	public void hide() {
		scrollPane.setVisible(false);
	}

	@Override
	/*public void setActionListener(ActionListener listener) {
		this.listener = listener;
	}*/

	public MaterialEstudoView getView() {
		return this;
	}
	
	@Override
	public void showError(Exception e) {
		JOptionPane.showMessageDialog(BackPanel, e.toString(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
	}
	
	//private void buildGUI(JPanel BackPanel) {
	private void buildGUI() {
		textArea.setText(materialEstudo.getConteudo());
		BackPanel.add(textArea);		
	}

	@Override
	public void setActionListener(ActionListener listener) {
		// TODO Auto-generated method stub
		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
	}

	
}
